<?php

/*
 * Edit by xinli
 * Click nbfs://nbhost/SystemFileSystem/Templates/Scripting/PHPClass.php to edit this template
 */

namespace api\mall\model;

/**
 * Description of CultureModel
 *
 * @author PC
 */
class CultureModel extends \think\Model
{
    protected $name = 'culture';
    
    protected $type = [
        'gallery' => 'array',
    ];


    /**
     * 后台管理添加页面
     * @param array $data 页面数据
     * @return $this
     */
    public function adminAddCulture($data)
    {
        $this->save($data);

        return $this;

    }

    /**
     * gallery 自动转化
     * @param $value
     * @return string
     */
    public function getGalleryAttr($value)
    {
        if (empty($value)) {
            return '';
        }

        $result = [];
        $value = json_decode($value, true);
        foreach ($value as $item) {
            $galleryItem = [];
            $galleryItem['url'] = $item['url'];
            $galleryItem['url_whole'] = cmf_get_image_url($item['url']);
            $galleryItem['name'] = $item['name'];
            $result[] = $galleryItem;
        }
        // $result = json_encode($result);
        return $result;
    }

    // /**
    //  * video 自动转化
    //  * @param $value
    //  * @return string
    //  */
    // public function getVideoAttr($value)
    // {
    //     if (empty($value)) {
    //         return '';
    //     }
    //     return cmf_get_image_url($value);
    // }

    /**
     * introduction 自动转化
     * @param $value
     * @return string
     */
    public function getIntroductionAttr($value)
    {
        if (empty($value)) {
            return '';
        }
        return cmf_replace_content_file_url(htmlspecialchars_decode($value));
    }

    /**
     * introduction 自动转化
     * @param $value
     * @return string
     */
    public function setIntroductionAttr($value)
    {
        if (empty($value)) {
            return '';
        }
        return htmlspecialchars(cmf_replace_content_file_url(htmlspecialchars_decode($value), true));
    }

}
